<?php
/**
 * 好友
 * @author HuangJie
 * @create_date 2008-02-25
 */

class Friend{
    function __construct(){}
    
    function __destruct(){}
    
    /* 增加好友   
     * @param : $arr_input - baby_id,baby_fid,group_id,friend_name,friend_nickname,friend_birthday,create_date
     */
    public function addFriend($conn,$arr_input){
        $str_query = "insert into";
        $str_query .= " baby_friend";
        $str_query .= " set";
        $str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= ",baby_fid={$arr_input['baby_fid']}";
        $str_query .= ",group_id={$arr_input['group_id']}";
        $str_query .= ",friend_name='{$arr_input['friend_name']}'";
        $str_query .= ",friend_nickname='{$arr_input['friend_nickname']}'";
        $str_query .= ",friend_birthday='{$arr_input['friend_birthday']}'";
        $str_query .= ",create_date='".$conn->getCurrentTime()."'";
        
        $conn->executeQuery($str_query);
    }
    
    /* 删除好友
     * @param : $arr_input - baby_id,baby_fid,group_id,friend_name,friend_nickname,friend_birthday,create_date
    */
    public function deleteFriend($conn,$arr_input){
    	$str_query = "delte from";
    	$str_query .= " baby_friend";
    	$str_query .= " where";
    	$str_query .= " baby_id={$arr_input['baby_id']}";
    	$str_query .= " and baby_fid={$arr_input['baby_fid']}";
    	
    	$conn->executeQuery($str_query);
    }
    
    /* 好友列表
     * @param : $arr_input - baby_id,baby_fid,group_id,friend_name,friend_nickname,friend_birthday,create_date
     * @return : $arr_output 
     *           baby_id,             [0]<br>
     *		     baby_fid,            [1]<br>
     *           group_id,            [2]<br>
     *		     friend_name,         [3]<br>
     *           friend_nickname,     [4]<br>
     *           friend_birthday,     [5]<br>
     *           create_date,         [6]<br>
    */
    public function getFriendList($conn,$arr_input,$limit = null){
    	$str_query = "select";
    	if(isset($arr_input['cnt'])){
    		$str_query .= " count(1)";
    	}else{
    		$str_query .= " baby_id";
    		$str_query .= " ,baby_fid";
    		$str_query .= " ,group_id";
    		$str_query .= " ,friend_name";
    		$str_query .= " ,friend_nickname";
    		$str_query .= " ,friend_birthday";
    		$str_query .= " ,create_date";
    	}
    	$str_query .=" from";
    	$str_query .=" baby_friend";
    	$str_query .=" where";
    	$str_query .=" baby_id={$arr_input['baby_id']}";
    	
    	if(isset($arr_input['baby_fid'])){
    		$str_query .=" and baby_fid={$arr_input['baby_fid']}";
    	}
    	if(isset($arr_input['group_id'])){
    		$str_query .=" and grout_id={$arr_input['group_id']}";
    	}
    	if (isset($arr_input['orderby'])) {
    		$str_query .= " order by {$arr_input['orderby']}";
    	}
    	if ($limit != null){
    		$str_query .= " {$limit}";
    	}

    	$arr_output = $conn->selectQuery($str_query);
    	return $arr_output;
    }
}
?>